# -*- coding: utf-8 -*-
from model import db, Collection
from time import time


class Video(Collection):
    '''
* `_id` (string) - 视频的 ID
* `createTime` (long) - 视频创建时间
* `title` (string) - 视频标题
* `description` (string) - 视频描述
* `imageUrl` (string) - 缩略图链接
* `updateTime` (long) - 视频最近一次更新时间
* `userId` (string) - 视频归属的老师的 ID，可为空
* `studioId` (string) - 视频归属的画室的 ID
* `videoUrl` (string) - 视频的链接
* `verified` (int) - 视频是否通过审核
    '''

    collection = db.video

    class Field(object):
        _id = '_id'
        createTime = 'createTime'
        title = 'title'
        description = 'description'
        imageUrl = 'imageUrl'
        updateTime = 'updateTime'
        userId = 'userId'
        studioId = 'studioId'
        verified = 'verified'
        videoUrl = 'videoUrl'

    class Verify(object):
        unverified = 0
        verified = 1

    @staticmethod
    def new_video(title, description, image_url, user_id, studio_id, video_url):
        return Video.insert({
            Video.Field.createTime: int(time() * 1000),
            Video.Field.title: title,
            Video.Field.description: description,
            Video.Field.imageUrl: image_url,
            Video.Field.userId: user_id,
            Video.Field.studioId: studio_id,
            Video.Field.updateTime: int(time() * 1000),
            Video.Field.verified: Video.Verify.verified,
            Video.Field.videoUrl: video_url
        })
